import { JXDef } from "../../conventions/JXCommon";
import { WinAddMode, WinCloseMode, WinLayer, WinMaskStatus, WinType } from "../../Core/CoreDefine";
import { MapWrap } from "../../Core/FrameEx/ES5Ex";
import { BASE_VIEW_ID_EX, WinInfo, WinInfos, WinModel } from "../../Core/Manager/UIMgr";
import { WinPage } from './../../Core/CoreDefine';
import { Res } from "./UIResources";

// var VIEW_ID_BASE = 1000000;
/** 所有的窗口ID */
export const VIEW_ID = JXDef.SYS_IDENTITY_ID;
/** 附上客户端的界面ID */
// cc.js.mixin(VIEW_ID, VIEW_ID);
cc.js.mixin(VIEW_ID, BASE_VIEW_ID_EX);

// 来个警告
if (CC_DEV) {
    let keys = Object.keys(VIEW_ID);
    for (let i = 0; i < keys.length; i++) {
        for (let j = 0; j < keys.length; j++) {
            if (i == j) continue
            if (VIEW_ID[keys[i]] == VIEW_ID[keys[j]]) {
                cc.warn(`${keys[i]}  == ${keys[j]}`)
            }
        }
    }
}


///////////////////////////////////////////////////////////////////////////// 窗口类型模板 //////////////////////////////////////////////////////////////////////
/** 通用全屏大窗口 */
const ComFullWin = new WinModel(WinType.FullView, WinMaskStatus.kOnlyShow, WinAddMode.ReplaceLayer, WinCloseMode.OnlyDestroy | WinCloseMode.PopAll, WinLayer.FirstWindow);
/** 通用全屏大窗口, 入栈本层之下的UI */
const ComFullStackWin = new WinModel(WinType.FullView, WinMaskStatus.kOnlyShow, WinAddMode.PushLower, WinCloseMode.OnlyDestroy | WinCloseMode.PopAll, WinLayer.FirstWindow);
/** 通用二级单例界面 */
const ComSecSingleWin = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.ReplaceSelf, WinCloseMode.OnlyDestroy, WinLayer.SecondWindow);
/** 通用二级堆叠界面 */
const ComSecWindow = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.SecondWindow);
/** 通用二级隐藏复用界面 */
const ComSecHidWindow = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.Hide, WinLayer.SecondWindow);
/** 通用全屏二级界面 */
const ComSecFullWinow = new WinModel(WinType.FullView, WinMaskStatus.kOnlyShow | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.SecondWindow);
/** 通用二级全屏单例界面 */
const ComSecFullSingleWin = new WinModel(WinType.FullView, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.ReplaceSelf, WinCloseMode.OnlyDestroy, WinLayer.SecondWindow);
/** 通用二级全屏单例界面-黑色背景 */
const CSFSBlackWin = new WinModel(WinType.FullView, WinMaskStatus.kOnlyShow | WinMaskStatus.kOpacity255, WinAddMode.ReplaceSelf, WinCloseMode.OnlyDestroy, WinLayer.SecondWindow);
/** 通用模态窗口 */
const ComThrWindow = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.ThirdWindow);
/** 通用三级单例窗口 */
const ComThrSingleWin = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.ReplaceSelf, WinCloseMode.OnlyDestroy, WinLayer.ThirdWindow);
/** 通用不可关闭模态窗口 */
const ComUnCloseThrWindow = new WinModel(WinType.Window, WinMaskStatus.kOnlyShow | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.ThirdWindow);

/** 通用频繁信息窗口 */
const ComTipWindow = new WinModel(WinType.Window, WinMaskStatus.kTouchClose | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.Recycle, WinLayer.ThirdWindow);
/** 通用频繁警告窗口 */
const ComUnTouckTipWindow = new WinModel(WinType.Window, WinMaskStatus.kOnlyShow | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.Recycle, WinLayer.WarnWindow);
/** 通用频繁警告窗口 */
const ComWarnWindow = new WinModel(WinType.Window, WinMaskStatus.kTouchClose, WinAddMode.Stack, WinCloseMode.Recycle, WinLayer.WarnWindow);


/** 通用顶层 */
const ComTopFix = new WinModel(WinType.Fix, WinMaskStatus.kOnlyShow, WinAddMode.ReplaceSelf, WinCloseMode.Recycle, WinLayer.TopWindow);
const ComTopFixConfirm = new WinModel(WinType.Fix, WinMaskStatus.kOnlyShow | WinMaskStatus.kOpacity156, WinAddMode.Stack, WinCloseMode.Recycle, WinLayer.TopWindow);
const ComWarnFix = new WinModel(WinType.Fix, WinMaskStatus.kNone, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.TopUpWindow);
const ComRollFix = new WinModel(WinType.Fix, WinMaskStatus.kNone | WinMaskStatus.kUnBlockInput, WinAddMode.Stack, WinCloseMode.OnlyDestroy, WinLayer.TopUpWindow);


/** 窗口预制件所以 */
const vw = Res.prefab.vw;

/** 窗口基本信息 */
export const JXWinInfo = new WinInfos(Object.keys(VIEW_ID).map((v, k) => VIEW_ID[v]), new MapWrap([
    [VIEW_ID.load, new WinInfo(vw.home.loadCtrl, ComFullWin)],
    [VIEW_ID.home, new WinInfo(vw.home.homeCtrl, ComFullWin)],
    [VIEW_ID.fightLayer, new WinInfo(vw.fight.fightLayer, ComFullStackWin)],
    [VIEW_ID.vip, new WinInfo(vw.home.vipCtrl, ComSecFullWinow)],
    [VIEW_ID.sginIn, new WinInfo(vw.home.signInCtrl, ComSecFullWinow)],
    [VIEW_ID.officer, new WinInfo(vw.home.officerCtrl, ComFullStackWin)],
    [VIEW_ID.detailsCtrl, new WinInfo(vw.home.detailsCtrl, ComFullStackWin)],
    [VIEW_ID.rewardCtrl, new WinInfo(vw.tip.rewardCtrl, ComSecFullWinow)],
    [VIEW_ID.levelCtrl, new WinInfo(vw.home.levelCtrl, ComSecSingleWin)],
    [VIEW_ID.blessCtrl, new WinInfo(vw.home.blessCtrl, ComSecFullWinow)],
    [VIEW_ID.battleResult, new WinInfo(vw.fight.battleResult, ComSecFullWinow)],
    [VIEW_ID.battleReward, new WinInfo(vw.fight.battleReward, ComSecFullWinow)],
    [VIEW_ID.towerCtrl, new WinInfo(vw.home.TowerCtrl, ComFullStackWin)],
    [VIEW_ID.EquipDetailsCtrl, new WinInfo(vw.home.EquipDetailsCtrl, ComUnCloseThrWindow)],
    [VIEW_ID.setting, new WinInfo(vw.home.setCtrl, ComSecSingleWin)],
    [VIEW_ID.skillPage, new WinInfo(vw.home.skillPage, ComUnCloseThrWindow)],
    [VIEW_ID.strengthenView, new WinInfo(vw.home.strengthenView, ComUnCloseThrWindow)],
    [VIEW_ID.currencyFrame, new WinInfo(vw.home.currencyFrame, ComUnCloseThrWindow)],
    [VIEW_ID.previewCtrl, new WinInfo(vw.home.previewCtrl, ComUnCloseThrWindow)],
    [VIEW_ID.featureCtrl, new WinInfo(vw.home.featureCtrl, ComUnCloseThrWindow)],
    [VIEW_ID.heroTry, new WinInfo(vw.hero.heroTry, ComUnCloseThrWindow)],
    [VIEW_ID.openBox, new WinInfo(vw.home.openBookCtrl, ComUnCloseThrWindow)],
    [VIEW_ID.recuitCardCtrl, new WinInfo(vw.home.recuitCardCtrl, ComUnCloseThrWindow)],

    [VIEW_ID.userInfoView, new WinInfo(vw.home.userInfoview, ComSecSingleWin)],
    [VIEW_ID.comonTipView, new WinInfo(vw.home.comonTipView, ComUnCloseThrWindow)],
    [VIEW_ID.friendView, new WinInfo(vw.home.friendView, ComSecFullWinow)],
    [VIEW_ID.emailView, new WinInfo(vw.home.emailView, ComSecFullWinow)],
    [VIEW_ID.homeCtrl, new WinInfo(vw.home.homeCtrl, ComSecFullWinow)],
    [VIEW_ID.rankCtrl, new WinInfo(vw.home.rankCtrl, ComSecFullWinow)],
    
    [VIEW_ID.dianjiangView, new WinInfo(vw.hero.dianjiangView, ComSecFullWinow)],
    [VIEW_ID.jiuguanView, new WinInfo(vw.home.jiuguanView, ComSecFullWinow)],
    [VIEW_ID.shopView, new WinInfo(vw.home.shopView, ComSecFullWinow)],
    [VIEW_ID.juntuanView, new WinInfo(vw.home.juntuanView, ComSecFullWinow)],
]));

/** 窗口静态预加载资源 */
export const JXViewPreLoad = {

}


export const VIEW_IDByPageNum: { [id: number]: { page?: number[], view?: number } } = {
    /** 主界面导航 */
    [VIEW_ID.mainPage]: { page: [WinPage.Page0], view: VIEW_ID.home },
    [VIEW_ID.heroPage]: { page: [WinPage.Page1], view: VIEW_ID.home },
    [VIEW_ID.chuangguanView]: { page: [WinPage.Page2], view: VIEW_ID.home },
    [VIEW_ID.squadPage]: { page: [WinPage.Page3], view: VIEW_ID.home },
    [VIEW_ID.bagView]: { page: [WinPage.Page4], view: VIEW_ID.home },
}

export const VIEW_PageNumByID: { [page: number]: { id?: number, view?: number } } = {
    [WinPage.Page0]: { id: VIEW_ID.mainPage, view: VIEW_ID.home },              //商店
    [WinPage.Page1]: { id: VIEW_ID.heroPage, view: VIEW_ID.heroPage },          //武将
    [WinPage.Page2]: { id: VIEW_ID.chuangguanView, view: VIEW_ID.chuangguanView },        //闯关
    [WinPage.Page3]: { id: VIEW_ID.chuangguanView, view: VIEW_ID.chuangguanView },        //试炼
    [WinPage.Page4]: { id: VIEW_ID.bagView, view: VIEW_ID.bagView },            //背包
}